# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     contours_utility
   Description :
   Author :       'li'
   date：          2021/9/7
-------------------------------------------------
   Change Activity:
                   2021/9/7:
-------------------------------------------------
"""
import cv2
import numpy as np


class ContoursUtility:
    @staticmethod
    def get_contours_image(mask):
        bg = np.zeros_like(mask)
        contours = ContoursUtility.get_contours(mask)
        for contour in contours:
            cv2.drawContours(bg, [contour], -1, 1, -1)
        return bg

    @staticmethod
    def get_filled_mask(bg, single_contours):
        """

        Args:
            bg:
            single_contours:

        Returns:

        """
        return cv2.drawContours(bg, [single_contours], -1, (1, 1, 1), -1)

    @staticmethod
    def get_contours(mask):
        """
        get contours of mask
        Args:
            mask:

        Returns:

        """
        bg = mask.astype(np.uint8)
        ret, thresh = cv2.threshold(bg, 127, 255, 0)
        contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        return contours
